<template>
  <el-dialog :title="result === 'REFUSE'? $t('确认驳回'): $t('确认通过') " :visible="true" class="dialogTaskDiapatch" width="550px" :modal="true" @close="close" append-to-body>
    <div>
      <div class="tip" v-if="result === 'REFUSE'">请确认驳回此单据，并输入审核意见</div>
      <div class="tip" v-if="result === 'AGREE'">请确认通过此单据</div>
      <el-form :model="dialogForm" ref="approveForm" label-width="88px">
        <el-form-item :label="$t('审批意见')" prop="task_comment" :rules="rf_rules({required: true})">
          <el-input
            type="textarea"
            :rows="3"
            placeholder="请输入意见"
            v-model="dialogForm.task_comment">
          </el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close()">{{$t('取消')}}</el-button>
      <el-button type="primary" @click="handleSubmit">{{$t('确定')}}</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import api from '../../utils/api'
  export default {
    props: {
      result: {
        type: String,
        default: 'REFUSE'
      },
      diaFormData: {
        type: Object,
        default: {}
      }
    },
    data () {
      return {
        dialogForm: {
          task_comment: ''
        }
      }
    },
    methods: {
      handleSubmit () {
        this.validateSubmit('approveForm').then(() => {
          let { request_code, task_id } = this.diaFormData
          let task_comment = this.dialogForm.task_comment
          let task_result = this.result === 'AGREE' ? 'Y' : 'N'
          let params = {
            request_code,
            task_id,
            task_comment,
            task_result
          }
          api.completeTask(params).then(res => {
            console.log(res)
            if (res.code === api.SUCCESS) {
              this.$messageTip('success')
              this.$emit('refreshData')
              this.close()
            }
          })
        })
      },
      close () {
        this.$emit('close')
      }
    }
  }
</script>
